package com.taptech.doufu.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

import com.taptech.doufu.manager.NovelEditManager;
import com.taptech.doufu.util.NetworkUtil;
import com.taptech.doufu.app.WeMediaApplication;
import com.taptech.doufu.event.EventBusSycnHistoryData;

import org.greenrobot.eventbus.EventBus;

public class NetBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            boolean isUsable = NetworkUtil.isNetworkUsable(WeMediaApplication.applicationContext);
            if (isUsable) {
                NovelEditManager.getInstance().uploadAllData();

                EventBusSycnHistoryData event = new EventBusSycnHistoryData();
                event.setTag(EventBusSycnHistoryData.tag);
                EventBus.getDefault().post(event);
            }
        }
    }
}
